//
//  SMHMineToolView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/4.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHMineToolView: LZBaseView {

    var viewModel : SMHMineViewModel?
    var setPayLab : UILabel?

    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as? SMHMineViewModel

        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:setupUI
    func setupUI() {
       
        let toolName :[String] = ["收款方式", "修改微信号", "收藏夹", "收货地址", "联系客服", "我的好友", "设置"]
        let toolImageName :[String] = ["icon_mine_payment","icon_mine_wechat","icon_mine_favorite","icon_mine_address","icon_mine_chatserver","icon_mine_friend","icon_mine_setting"]
    
        for i in 0..<toolName.count {
            let toolBtn = UIButton.init(type: .custom)
            toolBtn.setTitle(toolName[i], for: .normal)
            toolBtn.contentHorizontalAlignment = .left
            toolBtn.titleLabel?.font = ktextFont(size: 15)
            toolBtn.setTitleColor(UIColorFromHex(rgbValue: 0x363636), for: .normal)
            toolBtn.setImage(UIImage.init(named: toolImageName[i]), for: .normal)
            addSubview(toolBtn)
            toolBtn.snp.makeConstraints({ (make) in
                make.left.equalTo(15)
                make.width.equalTo(kScreenWidth - 60)
                make.top.equalTo(i * 55)
                make.height.equalTo(55)
            })
            toolBtn.layoutButtonEdgeInsets(style: .ButtonEdgeInsetsStyleLeft, space: 7)
            let imageView = UIImageView(image: UIImage.init(named: "ico_next_xiaojiantou"))
            toolBtn.addSubview(imageView)
            imageView.snp.makeConstraints { (make) in
                make.right.equalTo(-15)
                make.centerY.equalTo(toolBtn.snp.centerY)
                make.width.equalTo(7)
                make.height.equalTo(11)
            }
            toolBtn.addTarget(self, action: #selector(toolInfoClick), for: .touchUpInside)
           
            
            
            if i < toolName.count - 1 {
                let lineView = UIView()
                lineView.backgroundColor = UIColorFromHex(rgbValue: 0xE5E5E5)
                toolBtn.addSubview(lineView)
                lineView.snp.makeConstraints { (make) in
                    make.bottom.equalTo(0)
                    make.left.equalTo(-15)
                    make.right.equalTo(15)
                    make.height.equalTo(0.5)
                }
            }
       
            if i == 0{
                setPayLab = UILabel()
                setPayLab!.textAlignment = .right
                setPayLab!.text = "未设置"
                setPayLab!.textColor = UIColorFromHex(rgbValue: 0x868686)
                setPayLab!.font = ktextFont(size: 12)
                toolBtn.addSubview(setPayLab!)
                setPayLab!.snp.makeConstraints { (make) in
                    make.right.equalTo(-30)
                    make.width.equalTo(90)
                    make.height.equalTo(55)
                    make.centerY.equalTo(toolBtn.snp.centerY)
                }
            }
        }
    }
    //        let toolName :[String] = ["收款方式", "修改微信号", "收藏夹", "收货地址", "联系客服", "我的好友", "设置"]

    @objc func toolInfoClick(button:UIButton) {
        let currentTitle:String = button.currentTitle!
        
        
        switch currentTitle {
        case "设置":
            let settingVC = SMHSettingViewController()
            currentVC()?.navigationController?.pushViewController(settingVC, animated: true)

            
        case "我的好友":
            let friendVC = SMHFriendViewController()
            currentVC()?.navigationController?.pushViewController(friendVC, animated: true)

        case "联系客服":
            let webVC = LZWebViewController()
            webVC.webUrl = "http://m.sumaihuo.shop/contactUs.html"
            currentVC()?.navigationController?.pushViewController(webVC, animated: true)

        case "收货地址":
            let addressVC = SMHAddressViewController()
            currentVC()?.navigationController?.pushViewController(addressVC, animated: true)
            
        default: break
            
        }
        
        
        
        
    }

}
